<?php 
class product extends database{
	protected $_table = "product";
	protected $_image = "image";
	public function listproducts($type,$val){
		$sql = "select * from $this->_table where ".$type." =".$val;
		$this->query($sql);
		return $this->fetchall();
	}
	public function getProductById($id){
		$sql = "select * from $this->_table where pro_id = '$id'";
		if(is_numeric($id)){
			$this->query($sql);
			if($this->num_rows()>=1){
				return $this->fetch();
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
	public function getImageById($id){
		$sql = "select * from $this->_image,$this->_table where
				$this->_image.pro_id = $this->_table.pro_id and $this->_table.pro_id = '$id'
		";
		$this->query($sql);
		return $this->fetchall();
		}
	public function checkId($id){
		$sql = "select * from $this->_table";
		$this->query($sql);
		if($id > $this->num_rows() || $id < 1){
			return false;
		}else{
			return true;
			}
	}
	
	public function getpro_name($name){ 
	$sql = "select * from $this->_table where pro_name LIKE '%$name%'"; 
	$this->query($sql); 
	return $this->fetchall(); 
	}
	
	public function productRelated($productid,$brandid){
		$sql = "select * from $this->_table where pro_id != '$productid' and brand_id = '$brandid'";	
		$this->query($sql);
		return $this->fetchall();
	}
	public function getImageByIdRelated($productid,$brandid){
		$sql = "select * from $this->_image,$this->_table where
				$this->_image.pro_id = $this->_table.pro_id and $this->_table.pro_id != '$productid' and $this->_table.brand_id = '$brandid'
		";
		$this->query($sql);
		return $this->fetchall();
		}
}
?>